package week4.day23;

import java.io.*;

/**
 * @Author fengzihao
 * @Date 2024-05-07 19:56
 */
public class EncodeFIle {
    public static void main(String[] args) throws IOException {
        File encodingFile = new File("a.txt");
        File encodedFile = new File("b.txt");
        encodeFile(encodingFile,encodedFile);
    }
    public static void encodeFile(File encodingFile, File encodedFile) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(encodingFile);
        FileOutputStream fileOutputStream = new FileOutputStream(encodedFile,true);
        int num = -1;
        while ((num = fileInputStream.read())!=-1){
            if (Character.isDigit(num)){
                if (Character.getNumericValue(num)==9)
                    num = num-9;
                else
                    num = num+1;
            }
            if (Character.isLetter(num)){
                if (num=='z'||num=='Z')
                    num-=25;
                else
                    num++;
            }
            fileOutputStream.write(num);
        }
        fileInputStream.close();
        fileOutputStream.close();
    }
}
